package com.zixuan.gulicollege.cmsservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zixuan.gulicollege.cmsservice.mapper.CrmBannerMapper;
import com.zixuan.gulicollege.cmsservice.service.CrmBannerService;
import com.zixuan.gulicollege.entity.cms.CrmBanner;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author zixuan
 * @since 2021-05-16
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    @Cacheable(key = "'selectAllBanner'", value = "banner")
    @Override
    public List<CrmBanner> selectAllBanner() {
        // 根据gmt_create进行降序排列
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create");
        // 拼接sql
        wrapper.last("limit 3");
        return baseMapper.selectList(wrapper);
    }
}
